/**
 * 车型js
 */
//品牌改变
function emptySelect(targetSelect,desc){
    // $(targetSelect).select2({
    //     placeholder: desc,
    //     allowClear: false
    // });
    $(targetSelect).empty();
}
//品牌改变
$("#inTypeSelect1").change(function () {
    console.log("品牌改变");
    carBrand=$("#inTypeSelect1").find("option:selected").text();
    //清空车型
    // $("#inTypeSelect2").empty();
    // //清空年款
    // $("#inTypeSelect3").empty();
    // //清空版本
    // $("#inTypeSelect4").empty();
    emptySelect("#inTypeSelect2","选择车型");
    emptySelect("#inTypeSelect3","选择年款");
    emptySelect("#inTypeSelect4","选择排档版本");
    SelectMany2(contextPath+"/soa/base/cartypenew/datas/search/select","#inTypeSelect2","#inType2");
    // $("#inTypeSelect2").val('');
});
//车型改变
$("#inTypeSelect2").change(function () {
    carType=$("#inTypeSelect2").find("option:selected").text();
    //清空年款
    // $("#inTypeSelect3").empty();
    //清空版本
    // $("#inTypeSelect4").empty();
    emptySelect("#inTypeSelect3","选择年款");
    emptySelect("#inTypeSelect4","选择排档版本");
    SelectMany3(contextPath+"/soa/base/cartypenew/datas/search/select","#inTypeSelect3","#inType3");
});
//年款改变
$("#inTypeSelect3").change(function () {
    yearType=$("#inTypeSelect3").find("option:selected").text();
    //清空版本
    // $("#inTypeSelect4").empty();
    emptySelect("#inTypeSelect4","选择排档版本");
    SelectMany4(contextPath+"/soa/base/cartypenew/datas/search/select","#inTypeSelect4","#inType4");
});
$("#inTypeSelect4").change(function () {
    version=$("#inTypeSelect4").find("option:selected").text();
    //清空版本
    // $("#inTypeSelect4").empty();
    // emptySelect("#inTypeSelect4","选择排档版本");
    // SelectMany4(contextPath+"/soa/base/cartypenew/datas/search/select","#inTypeSelect4","#inType4");
});
function SelectMany1(comboxUrl, SelectTarget,hiddenId) {
    $.ajax({
        url: comboxUrl,
        type: "post",
        data:{"params":{},"column":1},
        dataType: "json",
        async: false,
        success: function (data) {
            var result=data.data;
            var $option = $('<option/>');
            $option.appendTo($(SelectTarget));
            for (var i = 0; i < result.length; i++) {
                var $option = $('<option/>').attr('value', result[i].id).html(result[i].carBrand);
                $option.appendTo($(SelectTarget));
            }

            $(SelectTarget).select2({
                placeholder: "选择品牌",
                allowClear: false
            }).change(function () {
                var hiddenTypeId = $(hiddenId);
                var zhi = $(SelectTarget).val();
                hiddenTypeId.attr("value", zhi);
            });

        }
    });
    var hiddenIdValue = $(hiddenId).val();
    if (hiddenIdValue != null && hiddenIdValue != "") {
        $(SelectTarget).val(hiddenIdValue).trigger("change");
    }
}
function SelectMany2(comboxUrl, SelectTarget,hiddenId) {
    $.ajax({
        url: comboxUrl,
        type: "post",
        data:{"params":{"carBrand":carBrand},"column":2},
        dataType: "json",
        async: false,
        success: function (data) {
            var result=data.data;
            var $option = $('<option/>');
            $option.appendTo($(SelectTarget));
            for (var i = 0; i < result.length; i++) {
                var $option = $('<option/>').attr('value', result[i].id).html(result[i].carType);
                $option.appendTo($(SelectTarget));
            }

            $(SelectTarget).select2({
                placeholder: "选择车型",
                allowClear: false
            }).change(function () {
                var hiddenTypeId = $(hiddenId);
                var zhi = $(SelectTarget).val();
                hiddenTypeId.attr("value", zhi);
            });

        }
    });
    var hiddenIdValue = $(hiddenId).val();
    if (hiddenIdValue != null && hiddenIdValue != "") {
        $(SelectTarget).val(hiddenIdValue).trigger("change");
    }
}
function SelectMany3(comboxUrl, SelectTarget,hiddenId) {
    $.ajax({
        url: comboxUrl,
        type: "post",
        data:{"params":{"carBrand":carBrand,"carType":carType},"column":3},
        dataType: "json",
        async: false,
        success: function (data) {
            var result=data.data;
            var $option = $('<option/>');
            $option.appendTo($(SelectTarget));
            for (var i = 0; i < result.length; i++) {
                var $option = $('<option/>').attr('value', result[i].id).html(result[i].yearType);
                $option.appendTo($(SelectTarget));
            }

            $(SelectTarget).select2({
                placeholder: "选择年款",
                allowClear: false
            }).change(function () {
                var hiddenTypeId = $(hiddenId);
                var zhi = $(SelectTarget).val();
                hiddenTypeId.attr("value", zhi);
            });

        }
    });
    var hiddenIdValue = $(hiddenId).val();
    if (hiddenIdValue != null && hiddenIdValue != "") {
        $(SelectTarget).val(hiddenIdValue).trigger("change");
    }
}
function SelectMany4(comboxUrl, SelectTarget,hiddenId) {
    $.ajax({
        url: comboxUrl,
        type: "post",
        data:{"params":{"carBrand":carBrand,"carType":carType,"yearType":yearType},"column":4},
        dataType: "json",
        async: false,
        success: function (data) {
            var result=data.data;
            var $option = $('<option/>');
            $option.appendTo($(SelectTarget));
            for (var i = 0; i < result.length; i++) {
                var $option = $('<option/>').attr('value', result[i].id).html(result[i].version);
                $option.appendTo($(SelectTarget));
            }

            $(SelectTarget).select2({
                placeholder: "选择排档版本",
                allowClear: false
            }).change(function () {
                var hiddenTypeId = $(hiddenId);
                var zhi = $(SelectTarget).val();
                hiddenTypeId.attr("value", zhi);
            });

        }
    });
    var hiddenIdValue = $(hiddenId).val();
    if (hiddenIdValue != null && hiddenIdValue != "") {
        $(SelectTarget).val(hiddenIdValue).trigger("change");
    }
}